//
// Created by ZLY on 2025/5/11.
//

#include "hud_skill.h"
#include "../affiliate/sprite.h"

HUDSkill *HUDSkill::addHUDSkillChild(Object *parent, const std::string &file_path, glm::vec2 pos, float scale,
                                     Anchor anchor) {
    auto hud_skill = new HUDSkill();
    hud_skill->init();
    hud_skill->icon_ = Sprite::addSpriteChild(hud_skill, file_path, scale, anchor);
    hud_skill->setRenderPos(pos);
    if (parent) {
        parent->addChild(hud_skill);
    }
    return hud_skill;
}

void HUDSkill::render() {
    //绘制浅色背景
    SDL_SetTextureColorModFloat(icon_->getTexture().texture, 0.3, 0.3, 0.3);
    auto pos = getRenderPos() + icon_->getOffset();
    game_.renderTexture(icon_->getTexture(), pos, icon_->getSize());
    SDL_SetTextureColorModFloat(icon_->getTexture().texture, 1.0, 1.0, 1.0);
    ObjectScreen::render();
}


void HUDSkill::setPercent(float percent) {
    percent = glm::clamp(percent, 0.0f, 1.0f);
    percent_ = percent;
    if (icon_) {
        icon_->setPercentage(glm::vec2(1.0f, percent));
    }
}
